﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Data.SqlClient;
using Net7Music_Api.Model;

namespace Net7Music_Api.DAL
{
    public class PlaylistServces
    {
        //查询全部歌单
        public static List<GetPlaylist_Result> Playlists()
        {
            string sql = "EXEC GetPlaylist";
            SqlDataReader dr = DBHelper.GetDataReader(sql);
            List<GetPlaylist_Result> getPlaylists = new();
            while (dr.Read())
            {
                GetPlaylist_Result getPlaylist = new()
                {
                    ID = dr.GetInt32(0),
                    PlaylistName = dr.GetString(1),
                    PlaylistImg = dr.GetString(2),
                    UserNickname = dr.GetString(3),
                };
                getPlaylists.Add(getPlaylist);
            }
            dr.Close();
            return getPlaylists;
        }
        //播放量最高的10条数据
        public static List<Playlist> PlaylistsHits()
        {
            string sql = "select top 8 * from Playlist where PlaylistName!='我喜欢的音乐' order by Hits desc";
            SqlDataReader dr = DBHelper.GetDataReader(sql);
            List<Playlist> Playlists = new();
            while (dr.Read())
            {
                Playlist Playlist = new()
                {
                    ID = dr.GetInt32(0),
                    PlaylistName = dr.GetString(1),
                    PlaylistImg = dr.GetString(2),
                    UserID = dr.GetInt32(3),
                    Hits = dr.GetInt32(4),
                };
                Playlists.Add(Playlist);
            }
            dr.Close();
            return Playlists;
        }
    }
}
